/*
 * @FileName: [RechargeableCardReconciliationController.java] 
 * @Package com.bcinfo.iccard.admin.iccard.controller 
 * 
 * 
 * Copyright (c) 2011-2015 BCINFO Technology Limited Com.
 * All rights reserved.
 * 
 * This software is the confidential and proprietary 
 * information of BCINFO Technology Limited Company
 * ("Confidential Information"). You shall not disclose 
 * such Confidential Information and shall use it only
 * in accordance with the terms of the contract agreement 
 * you entered into with RKY.
 * 
 * $Rev$
 * $LastChangedDate$
 * $LastChangedBy$
 * 
 * @category ICCARD
 * @version 1.1
 * @author $Author$
 *
 * Change History:[Formatter: author date description] <br/>
 * 1
 * 2
 * 3
*/


package com.bcinfo.iccard.admin.iccard.controller;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bcinfo.iccard.admin.common.ModuleEnum;
import com.bcinfo.iccard.admin.controller.AbstractController;
import com.bcinfo.iccard.exception.IccardException;
import com.bcinfo.iccard.service.RechargeableCardReconciliationService;
import com.bcinfo.iccard.util.PaginationList;

/**
 * 充值卡对账处理 <br/>
 * <p>Description:<br/>
 *    <p>充值卡对账处理
 *
 * <p>For Examples <br/>
 * <PRE>
 *      TODO 代码使用示例
 * </PRE>
 * <p>
 */

@Controller
@RequestMapping("/iccard/rcreconciliation")
public class RechargeableCardReconciliationController extends AbstractController
{
    @Autowired()
    private RechargeableCardReconciliationService rcrService;
    
    public String getMouduleCode()
    {
        return ModuleEnum.ComboCard.moduleName.value;
    }
    
    /**
     * 
     * 充值卡对账列表 <br/>
     * <p>Description: 充值卡对账列表
     * <br/>
     * <p>Author: zhaosl<br/>
     * <p>Date: 2013-12-20-上午10:44:59<br/>
     * <p>
     * @param cardName
     * @param status
     * @return   
     *
     */
    @RequestMapping("/list")
    @ResponseBody
    public Map<String, Object> list(String userId)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        PaginationList<Map<String,Object>> list = null;
        try
        {
            list = rcrService.getRechargeableCardList(userId, getPageSize(), getPage());
            if (list != null)
            {
                map.put("rows", list.getRecords());
                map.put("total", list.getTotalRecord());
            }
        }
        catch (IccardException e)
        {
            map.put("total", 0);
            handleException(e);
        }
        catch (Exception e)
        {
            map.put("total", 0);
            handleException(e);
        }

        return map;
    }
    
    /**
     * 销售人员对账列表 <br/>
     * <p>Description: TODO(详细描述) 
     * <br/>
     * <p>Author: zhaosl<br/>
     * <p>Date: 2013-12-20-下午4:10:03<br/>
     * <p>
     * @param userId
     * @param dzrq
     * @return   
     *
     */
    @RequestMapping("/dzlist")
    @ResponseBody
    public Map<String, Object> dzlist(String userId,String recentlyDate,String newDate,String opStatus)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        PaginationList<Map<String,Object>> list = null;
        try
        {
            list = rcrService.getReconciliationList(userId,recentlyDate,newDate,opStatus,getPageSize(), getPage());
            if (list != null)
            {
                map.put("rows", list.getRecords());
                map.put("total", list.getTotalRecord());
            }
        }
        catch (IccardException e)
        {
            map.put("total", 0);
            handleException(e);
        }
        catch (Exception e)
        {
            map.put("total", 0);
            handleException(e);
        }

        return map;
    }
    
    @ResponseBody
    @RequestMapping("/reconciliationSum")
    public Map<String, Object> reconciliationSum(String userId,String recentlyDate,String newDate,String opStatus)
    {
        Map<String, Object> map = new HashMap<String, Object>();
        try
        {
            String t = rcrService.getReconciliationSum(userId, recentlyDate,newDate,opStatus);
           if(StringUtils.isNotBlank(t))
            {
                map.put("rlsum", t);
            }else{
                map.put("rlsum", "0");
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return map;
    }
    
    @ResponseBody
    @RequestMapping("/checkCountReconciliation")
    public String checkCountReconciliation(String userId,String recentlyDate,String opStatus,String newDate,String hjje){
        String backRes = "1";
        
        try{
            backRes = rcrService.checkCountReconciliation(userId, recentlyDate, newDate, opStatus, String.valueOf(this.getCurrentOperator().getOperatorId()), hjje);
        }catch (Exception e)
        {
            e.printStackTrace();
        }
        return backRes;
    }

}
